﻿using System;
using System.Windows;

namespace LTemperaturos
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		private const string MUTEX_NAME = "LTemperaturos{22239A6C-FB60-485a-A3AA-BD0A2A1E37B0}";
		private static System.Threading.Mutex mutex;

		public App()
		{
			// check for another instance
			bool singleInstance;
			mutex = new System.Threading.Mutex(false, MUTEX_NAME, out singleInstance);

			if (!singleInstance)
			{
				MessageBox.Show("Programa jau yra veiksni. Galima tik viena programos veikianti kopija.", "Programa jau veikia.", MessageBoxButton.OK, MessageBoxImage.Warning);
				Shutdown(-1);
			}
			GC.KeepAlive(mutex);
		}

		protected override void OnExit(ExitEventArgs e)
		{
			mutex.Close();
			mutex = null;
			base.OnExit(e);
		}
	}
}
